var home = {
		//旷工管理
		workers : {
			
			type:"active",//默认有效旷工
			page:0,//默认首页
			size:20,//默认每页展示20条
			
			//初始化	
			init : function(){
				home.workers.getWorkers(home.workers.type,home.workers.page,home.workers.size,null);
				//选择
				$("#worker_active").change(function(){
					home.workers.type = $(this).val();
					home.workers.page = 0;
					home.workers.getWorkers(home.workers.type,home.workers.page,home.workers.size,null);
				});
				//绑定翻页事件
				$(".pageDiv").on("click","li",function(){
					var number = $(this).attr("page");
					if("<"==number){
						home.workers.page = parseInt(home.workers.page)-1;
					}else if(">"==number){
						home.workers.page = parseInt(home.workers.page)+1;
					}else{
						home.workers.page = parseInt(number);
					}
					home.workers.getWorkers(home.workers.type,home.workers.page,home.workers.size,null);

				});
				
				//搜索
				$("#searchBtn").click(function(){
					var workerName = $("#optsearch").val();
					if(workerName!=""){
						home.workers.getWorkers(home.workers.type,home.workers.page,home.workers.size,workerName);
					}
				});
				
			},
			getWorkers:function(type,page,size,workerName){
				$.post("/user/workers",{type:type,page:page,size:size,workerName:workerName},function(data){
					if(data.code=='200'){
						$(".workerContent").remove();
						var html = "";
						$.each(data.data.content,function(index,e){
							html+="<tr class=\"workerContent\"><td>"+e.workerName+"</td>";
							html+="<td>"+(parseFloat(e.accept1m*(Math.pow(256,4))/((Math.pow(10,12))*60)).toFixed(2))+"</td>";
							html+="<td>"+(parseFloat(e.accept5m*(Math.pow(256,4))/((Math.pow(10,12))*60*5)).toFixed(2))+"</td>";
							html+="<td>"+(parseFloat(e.accept15m*(Math.pow(256,4))/((Math.pow(10,12))*60*15)).toFixed(2))+"</td>";
							html+="<td>"+e.acceptCount+"</td>";
							html+="<td>"+e.rejectCount+"</td></tr>";
						});
						$("#worker-content-new tbody").append(html);
						//展示条数
						$(".workerCount").text(data.data.totalElements);
						//总页数
						var totalPages = data.data.totalPages;
						var pageDivHtml =""; 
						if(totalPages<=10){
							for (var i = 1; i <= totalPages; i++) {
								if((i-1)==page){
									pageDivHtml+="<li page='"+(i-1)+"' class='current'><a>"+i+"</a></li>";
								}else{
									pageDivHtml+="<li page='"+(i-1)+"'><a>"+i+"</a></li>";
								}
							}
						}else{
							if(page>0){
								pageDivHtml+="<li page='0'><a >1</a></li>";
							}
							if(page>1){
								pageDivHtml+="<li page='<'><a >&lt;</a></li>";
							}
							if(parseInt(page)-2>0){
								pageDivHtml+="<li page='"+ (parseInt(page)-2)+"'><a >"+(parseInt(page)-1)+"</a></li>";
							}
							if(parseInt(page)-1>0){
								pageDivHtml+="<li page='"+parseInt(page-1)+"'><a >"+(page)+"</a></li>";
							}
							pageDivHtml+="<li page='"+page+"' class='current'><a >"+(parseInt(page)+1)+"</a></li>";
							if((parseInt(page)+1)<(parseInt(totalPages)-1)){
								pageDivHtml+="<li page='"+(parseInt(page)+1)+"'><a >"+(parseInt(page)+2)+"</a></li>";
							}
							if((parseInt(page)+2)<(parseInt(totalPages)-1)){
								pageDivHtml+="<li page='"+(parseInt(page)+2)+"'><a >"+(parseInt(page)+3)+"</a></li>";
							}
							if((parseInt(page)+2)<(parseInt(totalPages)-2)){
								pageDivHtml+="<li page='>'><a >&gt;</a></li>";
							}
							if((parseInt(totalPages)-1)>page){
								pageDivHtml+="<li page='"+(parseInt(totalPages)-1)+"'><a >"+totalPages+"</a></li>";
							}
						}
						$(".pageDiv").html(pageDivHtml);
						
						
					}
				},'json');
			}
		},
		notice:{
			
			page:0,//默认首页
			size:20,//默认每页展示20条
			initText:"",
			successText:"",
			failText:"",
			
			init: function(initText,successText,failText){
				home.notice.initText=initText;
				home.notice.successText=successText;
				home.notice.failText=failText;
				//编辑
				$("#btn-e-e").click(function(){
					$("#user_NoticeShowForm :disabled").removeAttr("disabled");
					$("#btn-e-s, #btn-e-q").removeClass("dis-none");
					$(".user-note-tip").show();
					$(this).addClass("dis-none");
				});
				//保存
				$("#btn-e-s").on("click", function(){
					$.ajax({
						type : "POST",
						url : "/user/saveNoticeConfig",
						data : $('#user_NoticeShowForm').serialize(),
						dataType :"json",
						success : function(data) {
							if(data.code=='200') {
								window.location.href = "/home/notice";
							} else {
								$("#error_span").text(data.msg);
							}
						}
					});
				});
				//取消按钮事件
				$("#btn-e-q").on("click", function(){
					window.location.href = "/home/notice";
				});
				//数字输入框限制大于0
				$("#user_NoticeShowForm input[type='number']").blur(function(){
					var $that = $(this);
					if(parseFloat($that.val())<0){
						$that.val(0);
					}
				});
				
				home.notice.getNotices(home.notice.page,home.notice.size);
				
				//绑定翻页事件
				$(".pageDiv").on("click","li",function(){
					var number = $(this).attr("page");
					if("<"==number){
						home.notice.page = parseInt(home.notice.page)-1;
					}else if(">"==number){
						home.notice.page = parseInt(home.notice.page)+1;
					}else{
						home.notice.page = parseInt(number);
					}
					home.notice.getNotices(home.notice.page,home.notice.size);

				});

			},
			getNotices:function(page,size){
				$.post("/user/notices",{page:page,size:size},function(data){
					if(data.code=='200'){
						$(".noticeContent").remove();
						var html = "";
						$.each(data.data.content,function(index,e){
							html+="<tr class=\"noticeContent\"><td>"+e.id+"</td>";
							var msgText = e.message;
							html+="<td>"+msgText+"</td>";
							var statusText = "";
							if(e.status=="01"){
								statusText = home.notice.initText;
							}else if(e.status=="02"){
								statusText = home.notice.successText;
							}else if(e.status=="03"){
								statusText = home.notice.failText;
							}
							html+="<td>"+statusText+"</td>";
							html+="<td>"+new Date(e.noticeTime).Format("yyyy-MM-dd hh:mm:ss")+"</td></tr>";
						});
						$(".tbl2-user-note tbody").append(html);
						
						//总页数
						var totalPages = data.data.totalPages;
						var pageDivHtml =""; 
						if(totalPages<=10){
							for (var i = 1; i <= totalPages; i++) {
								if((i-1)==page){
									pageDivHtml+="<li page='"+(i-1)+"' class='current'><a>"+i+"</a></li>";
								}else{
									pageDivHtml+="<li page='"+(i-1)+"'><a>"+i+"</a></li>";
								}
							}
						}else{
							if(page>0){
								pageDivHtml+="<li page='0'><a >1</a></li>";
							}
							if(page>1){
								pageDivHtml+="<li page='<'><a >&lt;</a></li>";
							}
							if(parseInt(page)-2>0){
								pageDivHtml+="<li page='"+ (parseInt(page)-2)+"'><a >"+(parseInt(page)-1)+"</a></li>";
							}
							if(parseInt(page)-1>0){
								pageDivHtml+="<li page='"+parseInt(page-1)+"'><a >"+(page)+"</a></li>";
							}
							pageDivHtml+="<li page='"+page+"' class='current'><a >"+(parseInt(page)+1)+"</a></li>";
							if((parseInt(page)+1)<(parseInt(totalPages)-1)){
								pageDivHtml+="<li page='"+(parseInt(page)+1)+"'><a >"+(parseInt(page)+2)+"</a></li>";
							}
							if((parseInt(page)+2)<(parseInt(totalPages)-1)){
								pageDivHtml+="<li page='"+(parseInt(page)+2)+"'><a >"+(parseInt(page)+3)+"</a></li>";
							}
							if((parseInt(page)+2)<(parseInt(totalPages)-2)){
								pageDivHtml+="<li page='>'><a >&gt;</a></li>";
							}
							if((parseInt(totalPages)-1)>page){
								pageDivHtml+="<li page='"+(parseInt(totalPages)-1)+"'><a >"+totalPages+"</a></li>";
							}
						}
						$(".pageDiv").html(pageDivHtml);
						
						
					}
				},'json');
			}
		},
		income:{
			page:0,//默认首页
			size:20,//默认每页展示20条
			payMode:"",
			init:function(payMode){
				home.income.payMode = payMode;
				//绑定翻页事件
				$(".pageDiv").on("click","li",function(){
					var number = $(this).attr("page");
					if("<"==number){
						home.income.page = parseInt(home.income.page)-1;
					}else if(">"==number){
						home.income.page = parseInt(home.income.page)+1;
					}else{
						home.income.page = parseInt(number);
					}
					home.income.getIncomes(home.income.payMode,home.income.page,home.income.size);
				});
				
				home.income.getIncomes(home.income.payMode,home.income.page,home.income.size);
				
				//绑定收益切换事件
				$("#tablist a").click(function(){
					var $that = $(this);
					var name = $that.attr("name");
					if("ppshistory"==name){
						//FPPS
						home.income.payMode = "FPPS";
						home.income.getIncomes(home.income.payMode,home.income.page,home.income.size);
					}else if("ppappshistory"==name){
						//PPS
					}else if("refundhistory"==name){
						//收益
					}
					
				});
			},
			getIncomes:function(payMode,page,size){
				$.post("/user/income",{payMode:payMode,page:page,size:size},function(data){
					if(data.code=='200'){
						$(".incomeContent").remove();
						var html = "";
						$.each(data.data.content,function(index,e){
							html+="<tr class=\"incomeContent\"><td>"+new Date(e.miningDate).Format("yyyy-MM-dd")+"</td>";
							html+="<td>"+e.amount+"</td>";
							if(parseFloat(e.dayChange)>0){
								html+="<td style='color:red;'>+"+e.dayChange+"%</td>";
							}else{
								html+="<td style='color:gree;'>-"+e.dayChange+"%</td>";
							}
							html+="<td>"+new Date(e.payTime).Format("yyyy-MM-dd hh:mm:ss")+"</td>";
							html+="<td>"+e.walletAddr+"</td>";
						});
						$("#ppshistory tbody").append(html);
						
						//总页数
						var totalPages = data.data.totalPages;
						var pageDivHtml =""; 
						if(totalPages<=10){
							for (var i = 1; i <= totalPages; i++) {
								if((i-1)==page){
									pageDivHtml+="<li page='"+(i-1)+"' class='current'><a>"+i+"</a></li>";
								}else{
									pageDivHtml+="<li page='"+(i-1)+"'><a>"+i+"</a></li>";
								}
							}
						}else{
							if(page>0){
								pageDivHtml+="<li page='0'><a >1</a></li>";
							}
							if(page>1){
								pageDivHtml+="<li page='<'><a >&lt;</a></li>";
							}
							if(parseInt(page)-2>0){
								pageDivHtml+="<li page='"+ (parseInt(page)-2)+"'><a >"+(parseInt(page)-1)+"</a></li>";
							}
							if(parseInt(page)-1>0){
								pageDivHtml+="<li page='"+parseInt(page-1)+"'><a >"+(page)+"</a></li>";
							}
							pageDivHtml+="<li page='"+page+"' class='current'><a >"+(parseInt(page)+1)+"</a></li>";
							if((parseInt(page)+1)<(parseInt(totalPages)-1)){
								pageDivHtml+="<li page='"+(parseInt(page)+1)+"'><a >"+(parseInt(page)+2)+"</a></li>";
							}
							if((parseInt(page)+2)<(parseInt(totalPages)-1)){
								pageDivHtml+="<li page='"+(parseInt(page)+2)+"'><a >"+(parseInt(page)+3)+"</a></li>";
							}
							if((parseInt(page)+2)<(parseInt(totalPages)-2)){
								pageDivHtml+="<li page='>'><a >&gt;</a></li>";
							}
							if((parseInt(totalPages)-1)>page){
								pageDivHtml+="<li page='"+(parseInt(totalPages)-1)+"'><a >"+totalPages+"</a></li>";
							}
						}
						$(".pageDiv").html(pageDivHtml);
					}
				},'json');
			}
		}
}